﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ImageCropper.Lib
{
    public class Edge
    {
        private Direction _direction;
        private Axis _axis;        
        
        public Edge(Direction dir, double pos, double start, double end)
        {            
            this.Direction = dir;
            this.Position = pos;

            switch (this.Axis)
            {
                case Lib.Axis.NorthSouth:
                    this.Start = new Point(pos, start);
                    this.End = new Point(pos, end);
                    break;

                case Lib.Axis.EastWest:
                    this.Start = new Point(start, pos);
                    this.End = new Point(end, pos);
                    break;
            }
        }

        public Point Start { get; private set; }
        public Point End { get; private set; }
        
        public Direction Direction
        {
          get { return _direction; }
          set 
          { 
              _direction = value;

              switch (value)
              {
                  case Lib.Direction.North:
                  case Lib.Direction.South:
                      _axis = Lib.Axis.EastWest;
                      break;

                  case Lib.Direction.East:
                  case Lib.Direction.West:
                      _axis = Lib.Axis.NorthSouth;
                      break;                  
              }
          }
        }

        public Axis Axis { get { return _axis; } }
        
        public double Position { get; set; }

        public override bool Equals(object obj)
        {
            if (obj is Edge)
            {
                Edge e = obj as Edge;
                return this.Start == e.Start && this.End == e.End && this.Direction == e.Direction;
            }
            else
                return false;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return this.Start.GetHashCode() + this.End.GetHashCode() + this.Direction.GetHashCode();
            }
        }
    }
}
